package com.sure.classsystemserver.security.login;

import com.sure.classsystemserver.common.Result;
import com.sure.classsystemserver.common.TokenUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/security/login")
public class LoginAPI {

    @Resource
    private LoginService loginService;

    @PostMapping("")
    public Result login(@RequestBody LoginDto loginDto) {
        boolean ok = loginService.checkLogin(loginDto);

        if (ok) {
            String token = TokenUtils.loginSign(loginDto.getU_id(), loginDto.getU_pwd());
            return Result.success((Object) token);
        }else {
            return Result.fail(Result.ERR_CODE_BUSINESS,"账号或密码错误");
        }

    }
}
